package com.tianji.learning.controller;


import com.tianji.common.utils.BeanUtils;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.domain.query.PointsBoardQuery;
import com.tianji.learning.domain.vo.PointsBoardSeasonVO;
import com.tianji.learning.domain.vo.PointsBoardVO;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.tianji.learning.service.IPointsBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 学霸天梯榜 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2024-08-29
 */
@Api(tags = "排行榜相关接口")
@RestController
@RequestMapping("/boards")
@RequiredArgsConstructor
public class PointsBoardController {
    private final IPointsBoardService boardService;
    private final IPointsBoardSeasonService seasonService;

    /**
     * 查询当前榜单信息、我的排名和历史榜单信息、我的历史排名
     *
     * @param query
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询指定赛季的积分排行榜")
    public PointsBoardVO queryPointBoard(PointsBoardQuery query) {
        return boardService.queryPointBoard(query);
    }

    @GetMapping("/seasons/list")
    @ApiOperation("查询赛季列表")
    public List<PointsBoardSeasonVO> queryBodarList() {
        //1.获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //查询的赛季列表一定比当前时间要早
        List<PointsBoardSeason> list = seasonService.lambdaQuery().le(PointsBoardSeason::getBeginTime, now).list();
        //2.数据拷贝并返回
        return BeanUtils.copyList(list, PointsBoardSeasonVO.class);
    }
}
